/********************************************************************************
*   
*    Copyright (C) GREUAH: http://www.roboticaeducativa.es
*    Depecabot 3.0 project depecabot@depeca.uah.es
*
*********************************************************************************
*
*    This file is part of depecabot3 libs.
*
*    Depecabot3 libs is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    Depecabot3 libs is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    For a copy of the GNU General Public License see 
*    <http://www.gnu.org/licenses/>
*
********************************************************************************/

#ifndef Depecarduino_h
#define Depecarduino_h

#include <Arduino.h>
#include <Servo.h>
#include <Wire.h>
#include "PCD8544.h"

/********************Definiciones de pines*******************************/
#define P1 A4
#define P2 A3
#define P3 12

#define LED1 7
#define LED2 13

#define MI_B 6
#define MI_A 5
#define MD_B 10
#define MD_A 9

#define ENCODER1 11
#define ENCODER2 8

#define LCD_RST 13
#define LCD_SCE	7
#define LCD_DC	A0

#define VBAT A5

#define PUERTO4 A2 	//Lado puente H
#define PUERTO3 A1 
#define PUERTO2 12
#define PUERTO1 4	//Lado interruptor

#define SERVO PUERTO1

#define GP2 PUERTO4

/***********************Declaraciones de clases***************************/
class Encoder
{
	private:
		unsigned char pin;
	public:
		Encoder(unsigned char);
		unsigned int read();
		void reset();
};

class PCD8544_pixel: public PCD8544
{
	public:
		PCD8544_pixel():PCD8544(SCK,MOSI,LCD_DC,LCD_RST,LCD_SCE)		//Constructor
		{

		}		
		void writePixel(unsigned char, unsigned char, unsigned char);
		void refreshPixelMap(void);
	private:
		unsigned char * mapa;
};

class Depecarduino
{
	public:
		Depecarduino();
		void init();
		PCD8544_pixel lcd;
		void motores(int,int);
		void motoresLinealAngular(int,int);
		float bateria(void);
		Encoder encoder1;
		Encoder encoder2;
		Servo servo1;
		Servo servo2;
		unsigned char pulsador(unsigned char);
		unsigned int gp2dmm(unsigned char);
		unsigned int gp2ymm(unsigned char);
};

void encoderInit();
long readVcc(void);
int analogReadComp(int);

#endif
